package com.mobiletrain.org.motherkitch.shouye;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.mobiletrain.org.motherkitch.R;
import com.mobiletrain.org.motherkitch.utils.ImageLoad;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/4/27.
 */
public class PeoplePostAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<Post> data;

    public PeoplePostAdapter(Context context, ArrayList<Post> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if(data!=null){
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder3 holder3=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.post_list_item,null);
            holder3=new ViewHolder3();
            holder3.avatar= (ImageView) convertView.findViewById(R.id.post_avatar);
            holder3.nick= (TextView) convertView.findViewById(R.id.post_nickname);
            holder3.age_str= (TextView) convertView.findViewById(R.id.post_beiyun);
            holder3.show_date= (TextView) convertView.findViewById(R.id.post_time);
            holder3.content= (TextView) convertView.findViewById(R.id.post_content);
            convertView.setTag(holder3);

        }else{
            holder3= (ViewHolder3) convertView.getTag();
        }
        Post post = data.get(position);
        holder3.show_date.setText(post.getShow_date());
        holder3.nick.setText(post.getNickname());
        holder3.age_str.setText(post.getAge_str());
        holder3.content.setText(post.getContent());
        BitmapUtils bitmapUtils = ImageLoad.getBitmapUtils(context);
        bitmapUtils.display(holder3.avatar,post.getAvatar());

        return convertView;
    }
    class ViewHolder3{
        ImageView avatar;
        TextView nick;
        TextView age_str;
        TextView show_date;
        TextView content;
    }
}
